package com.shop2cn.iapi.agentproducts.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddProductBean;
import com.shop2cn.iapi.agentproducts.service.AddProductCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;

/**
 * OpenAPI(创建商品)Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddProduct {
	private static AddProductBean addproductBean;
	private static AddProductCall addproductCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("OpenAPI(创建商品)Test");
	}

	@Before
	public void caseUp() {
		addproductBean = new AddProductBean();
		addproductCall = new AddProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	private static int csId = AgentUsers.csId;
	private static String csName = "NickautoTest";
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	private static int csId1 = AgentUsers.csId1;
	// vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProduct_001() {
		Logger.start(true,"正确数据，成功");
		try {
			addproductBean = AddAgentProductCallService.initAddProduct(vipRootUserId,vipRootUserName,true);
			
			addproductCall.setData(addproductBean);
			addproductCall.callService();			
			Logger.verifyEquals("200", addproductCall.getString("code"), "验证code");
			String productId = addproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			
			AgentProductCallService.checkAddProduct(productId,addproductBean,false);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProduct_002() {
		Logger.start(true, "正确数据增加仓库，成功");
		try {
			
			addproductBean = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			createDepotBean bean = GodmchManageCallService.createDepot(vipRootUserId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService
					.SelectDepotByDepotTitle(bean.getDepotTitle());
			addproductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
//			addproductBean.setDepotName(selectDepotByDepotTitle.get(0).getDepotTitle());
			addproductCall.setData(addproductBean);
			addproductCall.callService();
			Logger.verifyEquals("200", addproductCall.getString("code"), "验证code");
			String productId = addproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId")
					.getAsString();
			Thread.sleep(2000);
			AgentProductCallService.checkAddProduct(productId, addproductBean, false);
			YmtProductsI ymtProductsI = new YmtProductsIWapper().selectProductByProductId(productId).get(0);
			Logger.verifyEquals(ymtProductsI.getiBondedArea(), selectDepotByDepotTitle.get(0).getDepotId(), "验证仓库");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProduct_003() {
		Logger.start(true,"中免商户创建，不生成小程序分享图");
		try {
			vipRootUserId=501024790;
			addproductBean = AddAgentProductCallService.initAddProduct(vipRootUserId,vipRootUserName,true);
			addproductCall.setData(addproductBean);
			addproductCall.callService();			
			Logger.verifyEquals("200", addproductCall.getString("code"), "验证code");
			String productId = addproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			
//			AgentProductCallService.checkAddProduct(productId,addproductBean,false);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}